package cn.jsp;

import cn.jsp.domain.Stu;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import cn.jsp.dao.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/rowProcessor")
public class RowProcessorServlet extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ApplicationContext ctx= WebApplicationContextUtils.getRequiredWebApplicationContext(req.getServletContext());
    BaseDao dao=ctx.getBean(BaseDao.class);
    List<Stu> stus=dao.query("select * from stu",rs->{
      Stu stu=new Stu();
      stu.setName(rs.getString("name"));
      return stu;
    });
    resp.getWriter().println(stus);
  }
}
